package net.kts.placebook.session;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

/*
 * 포스퀘어의 액세스 토큰을 관리
 */

public class FoursquareSession {
	private SharedPreferences sharedPref;
	private Editor editor;

	private static final String SHARED = "Foursquare_Preferences";
	private static final String FSQ_USERNAME = "username";
	private static final String FSQ_ACCESS_TOKEN = "access_token";

	public FoursquareSession(Context context) {
		// SharePreference 는 어플리케이션의 환경설정과 같은 간단한 데이터들을 저장할 수 있다
		sharedPref 	  = context.getSharedPreferences(SHARED, Context.MODE_PRIVATE);

		editor 		  = sharedPref.edit();
	}

	/**
	 * Save access token and user name
	 * 
	 * @param accessToken Access token
	 * @param username User name
	 */
	public void storeAccessToken(String accessToken) {
		// 저장
		Log.i("session accessToken store", accessToken);
		editor.putString(FSQ_ACCESS_TOKEN, accessToken);

		editor.commit();
	}

	/**
	 * Reset access token and user name
	 */
	public void resetAccessToken() {
		editor.putString(FSQ_ACCESS_TOKEN, null);
		editor.putString(FSQ_USERNAME, null);

		editor.commit();
	}

	/**
	 * Get access token
	 * 
	 * @return Access token
	 */
	public String getAccessToken() {
		
		Log.i("session accessToken get", FSQ_ACCESS_TOKEN);
		return sharedPref.getString(FSQ_ACCESS_TOKEN, null);
	}
}
